<template>
  <div>
    <a-card class="card" :bordered="false" :style="`min-height: ${cardMinHeight}px;`">
      <!--弹窗1的编辑弹窗4-->
      <a-modal
          destroyOnClose
          class="maintenance_detailsModal"
          v-model='maintenance_detailsModal'
          width='800px'
          :title="isAdd?'保养项目明细':title"
          @cancel="cancelDetailsModal"
          @ok="cancelDetailsModal"
          :bodyStyle="bodyStyle"
      >
        <a-spin :spinning="spinning">
          <a-table
              style="margin-top: 10px"
              :columns="maintenanceDetailsColumns"
              :data-source="maintenanceDetailsData"
              :pagination="maintenanceDetailsPagination"
              @change="onChangeMaintenanceDetails"
              :showPagination="true"
              :loading="tableLoadingMaintenanceDetails"
              :rowKey="(record1) => {return record1.index}"
              :scroll="{x:true,y: 165 }"
          >
            <template slot="action" slot-scope="record6">
              <a-popconfirm title="确定删除?" @confirm="() => delMaintenanceProject(record6)">
                <a>删除</a>
              </a-popconfirm>
            </template>
          </a-table>
        </a-spin>
      </a-modal>

      <!-- 新增编辑弹窗     -->
      <a-modal
          destroyOnClose
          class="maintenance_detailsModal"
          v-model='maintenance_detailsModal2'
          width='800px'
          :title="isAdd?'保养项目明细':title"
          @ok="cancelDetailsModal2"
          @cancel="cancelDetailsModal2"
          :bodyStyle="bodyStyle"
      >
        <a-spin :spinning="spinning">
          <div style="display: flex;justify-content: space-between;margin: 10px 0">
            <a-input style='width: 246px;height: 32px;' placeholder="*编码" v-model.trim="addFormOfNewDevice.code" :disabled="!canBeEdited || !isAdd"></a-input>
            <a-input style='width: 246px;height: 32px;' placeholder="*名称" v-model.trim="addFormOfNewDevice.name" :disabled="!canBeEdited || !isAdd"></a-input>
            <div style="width: 246px;display: flex;  justify-content:right">
              <a-button type="primary" style="margin-right: 15px" @click="clearAddMessage" :disabled="!canBeEdited || !isAdd">重置</a-button>
              <a-button type="primary" style="margin-right: 15px">快速拷贝</a-button>
              <a-button type="primary" @click="addMaintenanceProjectDetail()" :disabled="!canBeEdited || !isAdd|| !this.addFormOfNewDevice.code || !this.addFormOfNewDevice.name">添加</a-button>
            </div>

          </div>
          <a-table
              style="margin-top: 10px"
              :columns="maintenanceDetailsColumns"
              :data-source="maintenanceDetailsData"
              :pagination="maintenanceDetailsPagination"
              @change="onChangeMaintenanceDetails"
              :showPagination="true"
              :loading="tableLoadingMaintenanceDetails"
              :rowKey="(record1) => {return record1.index}"
              :scroll="{x:true,y: 165 }"
          >
            <template slot="action" slot-scope="record6">
              <a-popconfirm title="确定删除?" @confirm="() => delAddMaintenanceProject(record6)">
                <a>删除</a>
              </a-popconfirm>
            </template>
          </a-table>
        </a-spin>
      </a-modal>

      <!--弹窗0 新增按钮-->
      <a-modal
          destroyOnClose
          class="addModal"
          v-model='addModal'
          width='1100px'
          :title="isAdd?'新增':title"
          @cancel="handleCancel0"
          @ok="submitAndSaveDetailMore"
          :bodyStyle="bodyStyle"
      >
        <a-spin :spinning="spinning">
          <div style="width: 100%;min-height: 200px;display: flex;flex-direction: row;padding: 10px 24px 10px 24px;justify-content: center">
            <div style="width: 90%;">
              <a-form-model :model="basicForm"  layout="inline" ref="basicFormRef" :rules="rules">
                <a-form-model-item
                    required
                    label="编码"
                    prop="code"
                    style="margin-left: 30px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.code" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    label="规格型号"
                    prop="specificationsAndModels"
                    style="margin-left: 12px">
                  <a-input style='width: 350px;height: 32px;'  v-model.trim="basicForm.specification" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    required
                    label="名称"
                    prop="name"
                    style="margin-left: 30px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.name"  :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    label="生产厂家"
                    prop="manufacturer"
                    style="margin-left: 12px">
                  <a-popover trigger="click" placement="bottom" :overlayStyle="{ width: '350px' }">
                    <template slot="content">
                      <p class="aPopover" v-for="(item,index) in supplierSearchList" :key="index"  @click="changeSupplier(item)" >{{item.name}}</p>
                    </template>
                    <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.supplier_name"
                             @keydown.enter="getSupplierIdByNameLimit(basicForm.supplier_name)"
                             @change="getSupplierIdByNameLimit(basicForm.supplier_name)"
                             :disabled="!canBeEdited || !isAdd"
                             allowClear
                             @click="getSupplierIdByNameLimit(basicForm.supplier_name)"
                             placeholder="输入搜索并选择下方列表中生产厂家"
                    ></a-input>

                  </a-popover>

                </a-form-model-item>
                <a-form-model-item
                    label="出厂编号"
                    prop="factoryNumber"
                    style="margin-left: 14px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.factory_number"  :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    label="到厂日期"
                    prop="dateOfArrival"
                    style="margin-left: 12px">
                  <a-date-picker
                      format="YYYY-MM-DD"
                      show-time
                      placeholder="到厂日期"
                      v-model.trim="basicForm.arrival_date"
                      @change="onChangeArrivalDate"
                      :allow-clear="true"
                      style='width: 350px;height: 32px;'
                      :disabled="!canBeEdited || !isAdd"
                  />
                </a-form-model-item>
                <a-form-model-item
                    label="验收日期"
                    prop="acceptanceDate"
                    style="margin-left: 14px">
                  <a-date-picker
                      show-time
                      format="YYYY-MM-DD"
                      placeholder="验收日期"
                      v-model.trim="basicForm.acceptance_date"
                      @change="onChangeAcceptanceDate"
                      :allow-clear="true"
                      style='width: 350px;height: 32px;'
                      :disabled="!canBeEdited || !isAdd"
                  />
                </a-form-model-item>
                <a-form-model-item
                    label="设备状态"
                    prop="deviceStatus"
                    style="margin-left: 12px">
                  <a-select
                      style='width: 350px;height: 32px;'
                      @change="basicFormStatusChange"
                      v-model.trim="basicForm.status"
                      allow-clear
                      :disabled="!canBeEdited || !isAdd"
                  >
                    <a-select-option
                        v-for='item in basicForm.statusList2'
                        :key='item.code'
                        :value='item.code'
                    >{{item.description}}</a-select-option>
                  </a-select>
                </a-form-model-item>
                <a-form-model-item
                    label="质保验收"
                    prop="warrantyAcceptance"
                    style="margin-left: 14px">
<!--                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.warranty_acceptance_date"  :disabled="!canBeEdited || !isAdd"></a-input>-->
                  <a-date-picker
                      show-time
                      format="YYYY-MM-DD"
                      placeholder="质保验收"
                      v-model.trim="basicForm.warranty_acceptance_date"
                      @change="onChangeWarrantyAcceptanceDate"
                      allow-clear
                      style='width: 350px;height: 32px;'
                      :disabled="!canBeEdited || !isAdd"
                  />
                </a-form-model-item>
                <a-form-model-item
                    label="设备等级"
                    prop="deviceRating"
                    style="margin-left: 12px">
                  <a-select
                      style='width: 350px;height: 32px;'
                      allow-clear
                      @change="basicFormGradeChange"
                      v-model.trim="basicForm.device_grade_id"
                      :disabled="!canBeEdited || !isAdd"
                  >
                    <a-select-option
                        v-for='(item,index) in basicForm.allDeviceGradeList2'
                        :key='index'
                        :value='item.id'
                    >{{item.name}}</a-select-option>
                  </a-select>
                </a-form-model-item>
                <a-form-model-item
                    label="设备类型"
                    prop="deviceType"
                    style="margin-left: 14px">
                  <a-select
                      allow-clear
                      style='width: 350px;height: 32px;'
                      @change="basicFormTypeChange"
                      v-model.trim="basicForm.device_type_name"
                      :disabled="!canBeEdited || !isAdd"
                  >
                    <a-select-option
                        v-for='(item,index) in basicForm.typeList'
                        :key='index'
                        :value='item.id'
                    >{{item.name}}</a-select-option>
                  </a-select>
                </a-form-model-item>
                <a-form-model-item
                    label="设备功率"
                    prop="devicePower"
                    style="margin-left: 12px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.true_device_power" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    label="安装位置"
                    prop="installationLocation"
                    style="margin-left: 14px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.location" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    label="资产编码"
                    prop="assetCode"
                    style="margin-left: 12px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.asset_code" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    label="保养周期(小时)"
                    prop="serviceIntervals"
                    style="margin-left: 14px">
                  <a-input style='width: 315px;height: 32px;' v-model.trim="basicForm.maintenance_cycle" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    label="点检周期(小时)"
                    prop="spotCheckCycle"
                    style="margin-left: 12px">
                  <a-input style='width: 315px;height: 32px;' v-model.trim="basicForm.inspection_cycle"  :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
              </a-form-model>

            </div>
          </div>
          <!--标签页-->
          <div style="width: 100%;min-height: 250px;display: flex;flex-direction: row;padding: 10px 24px 0px 24px;border-top: 1px solid #ddd;">
            <a-tabs type="card" :activeKey="tabKey" @change="callback" :tabBarGutter="tabBarGutter" :tabBarStyle="tabBarStyle" style="width: 100%;">
              <a-tab-pane key="1" tab="备品备件" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <div style="display: flex;justify-content: space-between;margin-bottom: 10px;">
                      <a-popover trigger="focus" placement="bottom" :overlayStyle="{ width: '247px' }">
                        <template slot="content">
                          <p class="aPopover" v-for="(item,index) in partSearchList" :key="index"  @click="changePart(item)" >{{item.code}}</p>
                        </template>
                        <a-input style='width: 247px;height: 32px;'
                                 v-model.trim="addFormOfNewDevice.code"
                                 placeholder="*编码(搜索)"
                                 @keydown.enter="getPartListByPartCode(addFormOfNewDevice.code)"
                                 @change="getPartListByPartCode(addFormOfNewDevice.code)"
                                 @click="getPartListByPartCode(addFormOfNewDevice.code)"
                                 :disabled="!canBeEdited || !isAdd"></a-input>
                      </a-popover>

                      <a-popover trigger="focus" placement="bottom" :overlayStyle="{ width: '247px' }">
                        <template slot="content">
                          <p class="aPopover" v-for="(item,index) in partSearchList" :key="index"  @click="changePart(item)" >{{item.name}}</p>
                        </template>
                        <a-input style='width: 247px;height: 32px;'
                                 v-model.trim="addFormOfNewDevice.name" placeholder="*名称(搜索)"
                                 @keydown.enter="getPartListByPartName(addFormOfNewDevice.name)"
                                 @change="getPartListByPartName(addFormOfNewDevice.name)"
                                 @click="getPartListByPartName(addFormOfNewDevice.name)"
                                 :disabled="!canBeEdited || !isAdd"></a-input>
                      </a-popover>
                      <a-input style='width: 247px;height: 32px;' placeholder="规格" v-model.trim="addFormOfNewDevice.specification" disabled></a-input>
                      <div style="width: 247px;display: flex;  justify-content:right">
                        <a-button type="primary" style="margin-right: 15px" @click="clearAddMessage" :disabled="!canBeEdited || !isAdd">重置</a-button>
                        <a-button type="primary" @click="addPart" :disabled="!canBeEdited || !isAdd|| !this.addFormOfNewDevice.code || !this.addFormOfNewDevice.name">添加</a-button>
                      </div>

                    </div>
                    <a-table
                        :columns="key1Columns"
                        :data-source="key1Data"
                        :pagination="key1Pagination"
                        @change="onChangeKey1"
                        :showPagination="true"
                        :loading="tableLoading01"
                        :rowKey="(record1) => {return record1.index}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record1">
                        <a-popconfirm title="确定删除?" @confirm="() => delKey1Data(record1)">
                          <a>删除</a>
                        </a-popconfirm>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="2" tab="保养项目" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <div style="display: flex;justify-content: space-between;margin-bottom: 10px;">
                      <a-popover trigger="focus" placement="bottom" :overlayStyle="{ width: '330px' }">
                        <template slot="content">
                          <p class="aPopover" v-for="(item,index) in projectSearchList" :key="index"  @click="changeProject(item)" >{{item.code}}</p>
                        </template>
                        <a-input style='width: 330px;height: 32px;'
                                 v-model.trim="addFormOfNewDevice.code"
                                 placeholder="*编码(搜索)"
                                 @keydown.enter="getProjectTypeListByCode(addFormOfNewDevice.code)"
                                 @change="getProjectTypeListByCode(addFormOfNewDevice.code)"
                                 @click="getProjectTypeListByCode(addFormOfNewDevice.code)"
                                 :disabled="!canBeEdited || !isAdd"></a-input>
                      </a-popover>


                      <a-popover trigger="focus" placement="bottom" :overlayStyle="{ width: '330px' }">
                        <template slot="content">
                          <p class="aPopover" v-for="(item,index) in projectSearchList" :key="index"  @click="changeProject(item)" >{{item.name}}</p>
                        </template>
                        <a-input style='width: 330px;height: 32px;'
                                 v-model.trim="addFormOfNewDevice.name"
                                 placeholder="*名称(搜索)"
                                 @keydown.enter="getProjectTypeListByName(addFormOfNewDevice.name)"
                                 @change="getProjectTypeListByName(addFormOfNewDevice.name)"
                                 @click="getProjectTypeListByName(addFormOfNewDevice.name)"
                                 :disabled="!canBeEdited || !isAdd"></a-input>
                      </a-popover>
                      <div style="width: 330px;display: flex;  justify-content:right">
                        <a-button type="primary" style="margin-right: 15px" @click="clearAddMessage" :disabled="!canBeEdited || !isAdd">重置</a-button>
                        <a-button type="primary" @click="addMaintenanceProjectType" :disabled="!canBeEdited || !isAdd|| !this.addFormOfNewDevice.code || !this.addFormOfNewDevice.name">添加</a-button>
                      </div>

                    </div>
                    <a-table
                        :columns="key2Columns"
                        :data-source="key2Data"
                        :pagination="key2Pagination"
                        @change="onChangeKey2"
                        :showPagination="true"
                        :loading="tableLoading02"
                        :rowKey="(record2) => {return record2.index}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record2">
                        <a-popconfirm title="确定删除?" @confirm="() => delKey2Data(record2)">
                          <a>删除</a>
                        </a-popconfirm>
                          <a-divider type="vertical"/>
                          <a @click="maintenanceDetails2(record2)">编辑</a>

                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="3" tab="点检项目" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <div style="display: flex;justify-content: space-between;margin-bottom: 10px;">
                      <a-popover trigger="focus" placement="bottom" :overlayStyle="{ width: '330px' }">
                        <template slot="content">
                          <p class="aPopover" v-for="(item,index) in inspectProjectSearchList" :key="index"  @click="changeInspectProject(item)" >{{item.code}}</p>
                        </template>
                        <a-input style='width: 330px;height: 32px;'
                                 v-model.trim="addFormOfNewDevice.code"
                                 placeholder="*编码(搜索)"
                                 @keydown.enter="getInspectProjectListByCode(addFormOfNewDevice.code)"
                                 @change="getInspectProjectListByCode(addFormOfNewDevice.code)"
                                 @click="getInspectProjectListByCode(addFormOfNewDevice.code)"
                                 :disabled="!canBeEdited || !isAdd"></a-input>
                      </a-popover>


                      <a-popover trigger="focus" placement="bottom" :overlayStyle="{ width: '330px' }">
                        <template slot="content">
                          <p class="aPopover" v-for="(item,index) in inspectProjectSearchList" :key="index"  @click="changeInspectProject(item)" >{{item.name}}</p>
                        </template>
                        <a-input style='width: 330px;height: 32px;'
                                 v-model.trim="addFormOfNewDevice.name"
                                 placeholder="*名称(搜索)"
                                 @keydown.enter="getInspectProjectListByName(addFormOfNewDevice.name)"
                                 @change="getInspectProjectListByName(addFormOfNewDevice.name)"
                                 @click="getInspectProjectListByName(addFormOfNewDevice.name)"
                                 :disabled="!canBeEdited || !isAdd"></a-input>
                      </a-popover>


                      <div style="width: 330px;display: flex;  justify-content:right">
                        <a-button type="primary" style="margin-right: 15px" @click="clearAddMessage" :disabled="!canBeEdited || !isAdd">重置</a-button>
                        <a-button type='primary' style="margin-right: 15px">快速克隆</a-button>
                        <a-button type="primary" @click="addInspectProject" :disabled="!canBeEdited || !isAdd|| !this.addFormOfNewDevice.code || !this.addFormOfNewDevice.name">添加</a-button>

                      </div>

                    </div>
                    <a-table
                        :columns="key3Columns"
                        :data-source="key3Data"
                        :pagination="key3Pagination"
                        @change="onChangeKey3"
                        :showPagination="true"
                        :loading="tableLoading03"
                        :rowKey="(record3) => {return record3.index}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record3">
                        <a-popconfirm title="确定删除?" @confirm="() => delKey3Data(record3)">
                          <a>删除</a>
                        </a-popconfirm>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="4" tab="子设备" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <a-table
                        :columns="key4Columns"
                        :data-source="key4Data"
                        :pagination="key4Pagination"
                        @change="onChangeKey4"
                        :showPagination="true"
                        :loading="tableLoading01"
                        :rowKey="(record) => {return record.index}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record">
                        <a-popconfirm title="确定删除?" @confirm="() => delExtend(record.id)">
                          <a>删除</a>
                        </a-popconfirm>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="5" tab="联系人" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <a-table
                        :columns="key5Columns"
                        :data-source="key5Data"
                        :pagination="key5Pagination"
                        @change="onChangeKey5"
                        :showPagination="true"
                        :loading="tableLoading05"
                        :rowKey="(record5) => {return record5.index}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record5">
                        <a-popconfirm title="确定删除?" @confirm="() => delExtend(record5.id)">
                          <a>删除</a>
                        </a-popconfirm>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="6" tab="CMK" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 80%;">
                    <a-table
                        :columns="key6Columns"
                        :data-source="key6Data"
                        :pagination="key6Pagination"
                        @change="onChangeKey6"
                        :showPagination="true"
                        :loading="tableLoading06"
                        :rowKey="(record6) => {return record6.index}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record6">
                        <a-popconfirm title="确定删除?" @confirm="() => delExtend(record6.id)">
                          <a>删除</a>
                        </a-popconfirm>
                      </template>
                    </a-table>
                  </div>
                  <a-button type='primary' style="width: 14%;margin-left: 3%">快速克隆</a-button>
                </div>
              </a-tab-pane>
            </a-tabs>
          </div>
        </a-spin>

      </a-modal>


      <!--弹窗1详情-->
      <a-modal
          destroyOnClose
          class="detailModal"
          v-model='detailModal'
          width='1100px'
          :title="canBeQuery?'详情':title"
          @ok="submitAndSaveDetail"
          @cancel="handleCancel1"
          :bodyStyle="bodyStyle"
      >
        <a-spin :spinning="spinning">
          <div style="width: 100%;min-height: 200px;display: flex;flex-direction: row;padding: 10px 24px 10px 24px;justify-content: center">
            <div style="width: 90%;">
              <a-form-model :model="basicForm"  layout="inline" ref="basicFormRef" :rules="rules">
                <a-form-model-item
                    required
                    label="编码"
                    prop="code"
                    style="margin-left: 30px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.code" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    label="规格型号"
                    prop="specificationsAndModels"
                    style="margin-left: 12px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.specification" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    required
                    label="名称"
                    prop="name"
                    style="margin-left: 30px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.name" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    label="生产厂家"
                    prop="manufacturer"
                    style="margin-left: 12px">
                  <a-popover trigger="click" placement="bottom" :overlayStyle="{ width: '350px' }">
                    <template slot="content">
                      <p class="aPopover" v-for="(item,index) in supplierSearchList" :key="index"  @click="changeSupplier(item)" >{{item.name}}</p>
                    </template>
                      <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.supplier_name"
                               @click="getSupplierIdByNameLimit(basicForm.supplier_name)"
                               @keydown.enter="getSupplierIdByNameLimit(basicForm.supplier_name)"
                               @change="getSupplierIdByNameLimit(basicForm.supplier_name)"
                               allowClear
                               :disabled="!canBeEdited || !isAdd"></a-input>
                  </a-popover>
                </a-form-model-item>
                <a-form-model-item
                    label="出厂编号"
                    prop="factoryNumber"
                    style="margin-left: 13px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.factory_number" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    label="到厂日期"
                    prop="dateOfArrival"
                    style="margin-left: 12px">
                      <a-date-picker
                          format="YYYY-MM-DD"
                          show-time
                          placeholder="到厂日期"
                          v-model.trim="basicForm.arrival_date"
                          @change="onChangeArrivalDate"
                          allowClear
                          style='width: 350px;height: 32px;'
                          :disabled="!canBeEdited || !isAdd"
                      />
                </a-form-model-item>
                <a-form-model-item
                    label="验收日期"
                    prop="acceptanceDate"
                    style="margin-left: 13px">
                  <a-date-picker
                      show-time
                      format="YYYY-MM-DD"
                      placeholder="验收日期"
                      v-model.trim="basicForm.acceptance_date"
                      @change="onChangeAcceptanceDate"
                      allowClear
                      style='width: 350px;height: 32px;'
                      :disabled="!canBeEdited || !isAdd"
                  />
                </a-form-model-item>
                <a-form-model-item
                    label="设备状态"
                    prop="deviceStatus"
                    style="margin-left: 12px">
                  <a-select
                      style='width: 350px;height: 32px;'
                      allowClear
                      @change="basicFormStatusChange"
                      v-model.trim="basicForm.status_description"
                      :disabled="!canBeEdited || !isAdd"
                  >
                    <a-select-option
                        v-for='item in basicForm.statusList2'
                        :key='item.code'
                        :value='item.code'
                    >{{item.description}}</a-select-option>
                  </a-select>
                </a-form-model-item>
                <a-form-model-item
                    label="设备类型"
                    prop="deviceType"
                    style="margin-left: 13px">
                  <a-select
                      allowClear
                      style='width: 350px;height: 32px;'
                      @change="basicFormTypeChange"
                      v-model.trim="basicForm.device_type_name"
                      :disabled="!canBeEdited || !isAdd"
                  >
                    <a-select-option
                        v-for='(item,index) in basicForm.typeList'
                        :key='index'
                        :value='item.id'
                    >{{item.name}}</a-select-option>
                  </a-select>
                </a-form-model-item>
                <a-form-model-item
                    label="设备等级"
                    prop="deviceRating"
                    style="margin-left: 12px">
                  <a-select
                      style='width: 350px;height: 32px;'
                      allowClear
                      @change="basicFormGradeChange"
                      v-model.trim="basicForm.device_grade_id"
                      :disabled="!canBeEdited || !isAdd"
                  >
                    <a-select-option
                        v-for='(item,index) in basicForm.allDeviceGradeList2'
                        :key='index'
                        :value='item.id'
                    >{{item.name}}</a-select-option>
                  </a-select>
                </a-form-model-item>

                <a-form-model-item
                    label="安装位置"
                    prop="installationLocation"
                    style="margin-left: 13px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.location" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>
                <a-form-model-item
                    label="资产编码"
                    prop="assetCode"
                    style="margin-left: 12px">
                  <a-input style='width: 350px;height: 32px;' v-model.trim="basicForm.asset_code" :disabled="!canBeEdited || !isAdd"></a-input>
                </a-form-model-item>

              </a-form-model>


            </div>
          </div>
          <!--标签页-->
          <div style="width: 100%;min-height: 250px;display: flex;flex-direction: row;padding: 10px 24px 0px 24px;border-top: 1px solid #ddd;">
            <a-tabs type="card" :activeKey="tabKey" @change="callback" :tabBarGutter="tabBarGutter" :tabBarStyle="tabBarStyle" style="width: 100%;">
              <a-tab-pane key="1" tab="备品备件" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <a-table
                        :columns="detail1Columns"
                        :data-source="detail1Data"
                        :pagination="detail1Pagination"
                        @change="onChangeDetail1"
                        :showPagination="true"
                        :loading="tableLoadingDetail1"
                        :rowKey="(record1) => {return record1.id}"
                        :scroll="{x:true,y: 165 }"
                    >
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="2" tab="保养记录" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <a-table
                        :columns="detail2Columns"
                        :data-source="detail2Data"
                        :pagination="detail2Pagination"
                        @change="onChangeDetail2"
                        :showPagination="true"
                        :loading="tableLoadingDetail2"
                        :rowKey="(record2) => {return record2.id}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record2">
                          <a>详情</a>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="3" tab="点检记录" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <a-table
                        :columns="detail3Columns"
                        :data-source="detail3Data"
                        :pagination="detail3Pagination"
                        @change="onChangeDetail3"
                        :showPagination="true"
                        :loading="tableLoadingDetail3"
                        :rowKey="(record3) => {return record3.id}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record3">
                        <a>详情</a>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="4" tab="维修记录" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <a-table
                        :columns="detail4Columns"
                        :data-source="detail4Data"
                        :pagination="detail4Pagination"
                        @change="onChangeDetail4"
                        :showPagination="true"
                        :loading="tableLoadingDetail4"
                        :rowKey="(record4) => {return record4.id}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record4">
                        <a>详情</a>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="5" tab="子设备" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <a-table
                        :columns="detail5Columns"
                        :data-source="detail5Data"
                        :pagination="detail5Pagination"
                        @change="onChangeDetail5"
                        :showPagination="true"
                        :loading="tableLoadingDetail5"
                        :rowKey="(record5) => {return record5.id}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record5">
                        <a>详情</a>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="6" tab="保养项目" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <a-table
                        :columns="detail6Columns"
                        :data-source="detail6Data"
                        :pagination="detail6Pagination"
                        @change="onChangeDetail6"
                        :showPagination="true"
                        :loading="tableLoadingDetail6"
                        :rowKey="(record6) => {return record6.id}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record6">
                          <a-popconfirm title="确定删除?" @confirm="() => delMaintenanceProjectType(record6)">
                            <a>删除</a>
                          </a-popconfirm>
                        <a-divider type="vertical"/>
                        <a @click="maintenanceDetails(basicForm.id,record6.id)">编辑</a>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="7" tab="点检项目" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <a-table
                        :columns="detail7Columns"
                        :data-source="detail7Data"
                        :pagination="detail7Pagination"
                        @change="onChangeDetail7"
                        :showPagination="true"
                        :loading="tableLoadingDetail7"
                        :rowKey="(record7) => {return record7.id}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record7">
                          <a-popconfirm title="确定删除?" @confirm="() => delExtend(record7.id)">
                            <a>删除</a>
                          </a-popconfirm>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="8" tab="改造记录" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <a-table
                        :columns="detail8Columns"
                        :data-source="detail8Data"
                        :pagination="detail8Pagination"
                        @change="onChangeDetail8"
                        :showPagination="true"
                        :loading="tableLoadingDetail8"
                        :rowKey="(record8) => {return record8.id}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record8">
                          <a>详情</a>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="9" tab="处置记录" :force-render="true">
                <div style="width: 100%;display: flex;flex-direction: row;">
                  <div style="width: 100%;">
                    <a-table
                        :columns="detail9Columns"
                        :data-source="detail9Data"
                        :pagination="detail9Pagination"
                        @change="onChangeDetail9"
                        :showPagination="true"
                        :loading="tableLoadingDetail9"
                        :rowKey="(record9) => {return record9.id}"
                        :scroll="{x:true,y: 165 }"
                    >
                      <template slot="action" slot-scope="record9">
                        <a>详情</a>
                      </template>
                    </a-table>
                  </div>
                </div>
              </a-tab-pane>
              <a-tab-pane key="10" tab="联系人" :force-render="true">
              </a-tab-pane>
              <a-tab-pane key="11" tab="CMK" :force-render="true">
              </a-tab-pane>

            </a-tabs>
          </div>
        </a-spin>
      </a-modal>

      <!--弹窗2改造-->
      <a-modal
          destroyOnClose
          class="remodelModal"
          v-model='remodelModal'
          width='800px'
          :title="canBeQuery?'改造':title"
          @cancel="handleCancel"
          :bodyStyle="bodyStyle"
          @ok="reformReasonSubmit"
      >
        <a-spin :spinning="spinning">
          <a-form>
            <div style="margin:15px 5%;">
              <a-form-item label="改造原因">
                <a-textarea v-model.trim="reformReason" show-count :maxlength="100" />
              </a-form-item>
              <a-form-item label="上传附件">
                <a-upload
                          v-model:file-list="fileList"
                          :multiple="false"
                          accept=".png,.jpg,.jpeg,.doc,.docx,.xls,.xlsx,.pdf,.txt"
                          :remove="handleDownloadFileRemove"
                          :before-upload="beforeUpload"
                          :file-list="fileList"
                >
                  <a-button icon="upload">
                    Upload
                  </a-button>
                </a-upload>
              </a-form-item>
            </div>
          </a-form>
        </a-spin>
      </a-modal>

      <!--弹窗3处置-->
      <a-modal
          destroyOnClose
          class="disposalModal"
          v-model='disposalModal'
          width='800px'
          :title="canBeQuery?'处置':title"
          @cancel="handleCancel2"
          :bodyStyle="bodyStyle"
          @ok="manageTextSubmit"
      >
        <a-spin :spinning="spinning">
          <!--标签页-->
          <div style="width: 100%;min-height: 250px;display: flex;flex-direction: row;padding: 10px 24px 0px 24px;border-top: 1px solid #ddd;">
            <a-tabs type="card" :activeKey="tabKey" @change="callback" :tabBarGutter="tabBarGutter" :tabBarStyle="tabBarStyle" style="width: 100%;">
              <a-tab-pane key="1" tab="报废">
                <a-form>
                  <div style="margin-right: 5%;margin-left: 5%;">
                    <a-form-item label="报废原因">
                      <a-textarea v-model.trim="manageText" show-count :maxlength="100" />
                    </a-form-item>
                    <a-form-item label="上传附件">
                      <a-upload
                          v-model:file-list="fileList"
                          :multiple="false"
                          accept=".png,.jpg,.jpeg,.doc,.docx,.xls,.xlsx,.pdf,.txt"
                          :remove="handleDownloadFileRemove"
                          :before-upload="beforeUpload"
                          :file-list="fileList"
                      >
                        <a-button icon="upload">
                          Upload
                        </a-button>
                      </a-upload>
                    </a-form-item>
                  </div>
                </a-form>
              </a-tab-pane>

              <a-tab-pane key="2" tab="封存">
                <a-form>
                  <div style="margin-right: 5%;margin-left: 5%;">
                    <a-form-item label="封存原因">
                      <a-textarea v-model.trim="manageText" show-count :maxlength="100" />
                    </a-form-item>
                    <a-form-item label="上传附件">
                      <a-upload
                          v-model:file-list="fileList"
                          :multiple="false"
                          accept=".png,.jpg,.jpeg,.doc,.docx,.xls,.xlsx,.pdf,.txt"
                          :remove="handleDownloadFileRemove"
                          :before-upload="beforeUpload"
                          :file-list="fileList"
                      >
                        <a-button icon="upload">
                          Upload
                        </a-button>
                      </a-upload>
                    </a-form-item>

                    <a-form-item label="封存前保养:">
                      <a-select
                          :is-multiple="false"
                          style='width: 150px'
                          v-model.trim='maintenanceType'
                          v-auth="`query`"
                          allow-clear
                      >
                        <a-select-option
                            v-for='(item,index) in maintenanceTypeList'
                            :key='index'
                            :value='item.id'
                        >{{item.name}}</a-select-option>
                      </a-select>
                    </a-form-item>

                  </div>
                </a-form>
              </a-tab-pane>
              <a-tab-pane key="3" tab="启动">
                <a-form>
                  <div style="margin-right: 5%;margin-left: 5%;">
                    <a-form-item label="启用原因">
                      <a-textarea v-model.trim="manageText" show-count :maxlength="100" />
                    </a-form-item>
                    <a-form-item label="上传附件">
                      <a-upload
                          v-model:file-list="fileList"
                          :multiple="false"
                          accept=".png,.jpg,.jpeg,.doc,.docx,.xls,.xlsx,.pdf,.txt"
                          :remove="handleDownloadFileRemove"
                          :before-upload="beforeUpload"
                          :file-list="fileList"
                      >
                        <a-button icon="upload">
                          Upload
                        </a-button>
                      </a-upload>
                    </a-form-item>
                  </div>
                </a-form>
              </a-tab-pane>
              <a-tab-pane key="4" tab="异动">
                <a-form>
                  <div style="margin-right: 5%;margin-left: 5%;">
                    <a-form-item label="异动原因">
                      <a-textarea v-model.trim="manageText" show-count :maxlength="100" />
                    </a-form-item>
                    <a-form-item label="上传附件">
                      <a-upload
                          v-model:file-list="fileList"
                          :multiple="false"
                          accept=".png,.jpg,.jpeg,.doc,.docx,.xls,.xlsx,.pdf,.txt"
                          :remove="handleDownloadFileRemove"
                          :before-upload="beforeUpload"
                          :file-list="fileList"
                      >
                        <a-button icon="upload">
                          Upload
                        </a-button>
                      </a-upload>
                    </a-form-item>

                    <a-form-item label="异动部门:">
                      <a-select
                          :is-multiple="false"
                          style='width: 150px'
                          allow-clear
                          v-model.trim='department'
                          v-auth="`query`"
                      >
                        <a-select-option
                            v-for='(item,index) in organizationList'
                            :key='index'
                            :value='item.id'
                        >{{item.name}}</a-select-option>
                      </a-select>
                    </a-form-item>

                  </div>
                </a-form>
              </a-tab-pane>
            </a-tabs>
          </div>
        </a-spin>
      </a-modal>

      <page-head-area>
        <div class="extra" style="width: 200px;display: flex;justify-content: space-around">
          <a-button icon="plus-circle" v-auth="`insert`" @click="add" style="background-color: #fff;border: none;margin-left: 10px;width: 70px;height: 35px;">新增</a-button>

          <a-popconfirm
              title="确定删除吗?"
              ok-text="确定"
              cancel-text="取消"
              @confirm="deleteDevice"
          >
          <a-button icon="delete" v-auth="`delete`" style="background-color: #fff;border: none;margin-left: 10px;width: 70px;height: 35px;"
                    >删除</a-button>
          </a-popconfirm>
        </div>
      </page-head-area>

      <div class="queryBox">
        <a-form-model layout="inline" :model='queryForm'  ref="queryFormRef" class='query' style='display: flex;flex-wrap: wrap;'>
        <a-form-model-item
            class='optionTitle'
            label="编码"
            prop="code"
            style="margin-left: 0"
        >
          <a-input style='width: 200px;height: 32px' v-model='queryForm.code' v-auth="`query`"></a-input>
        </a-form-model-item>
        <a-form-model-item
            class='optionTitle'
            label="名称"
            prop="name"
        >
          <a-input style='width: 200px;height: 32px' v-model='queryForm.name'  v-auth="`query`"></a-input>
        </a-form-model-item>

        <a-form-model-item
            class='optionTitle'
            label="规格"
            prop="specification"
        >
          <a-input style='width: 200px;height: 32px' v-model='queryForm.specification' v-auth="`query`"></a-input>
        </a-form-model-item>

        <a-form-model-item
            label="状态"
            prop="status"
            style=""
            ref="statusRef"
        >
          <a-select
              :is-multiple="false"
              style='width: 150px'
              allow-clear
              v-model.trim='queryForm.mask_status'
              v-auth="`query`"
          >
            <a-select-option
                v-for='(item,index) in basicForm.statusList'
                :key='index'
                :value='item.code'
            >{{item.description}}</a-select-option>
          </a-select>
        </a-form-model-item>

        <a-form-model-item
            label="等级"
            prop="grade"
            style=""
            ref="gradeRef"
        >
          <a-select
              :is-multiple="false"
              style='width: 150px'
              allow-clear
              v-model.trim='queryForm.mask_grades'
              v-auth="`query`"
          >
            <a-select-option
                v-for='(item,index) in basicForm.allDeviceGradeList'
                :key='index'
                :value='item.id'
            >{{item.name}}</a-select-option>
          </a-select>
        </a-form-model-item>

          <a-form-model-item>
            <a-button type='primary' style='height: 32px;width: 70px;text-align: center' @click="reset" v-auth="`query`">
              重置
            </a-button>
          </a-form-model-item>

          <a-form-model-item>
            <a-button type='primary' style='height: 32px;width: 70px;text-align: center' @click="filter" v-auth="`query`">
              搜索
            </a-button>
          </a-form-model-item>
        </a-form-model>
      </div>
      <div class="dataBox">
        <a-table
            :columns="columns"
            :data-source="data"
            :loading="tableLoading"
            :pagination="false"
            :rowKey="(recordMain) => {return recordMain.id}"
            :scroll="{ x: 1000, y: 500 }"
            :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        >
          <template slot="action" slot-scope="record">
            <a v-auth="`query`" @click="detail(record)">详情</a>
            <a-divider type="vertical"/>
            <a v-auth="`update`" @click="remodel(record)">改造</a>
            <a-divider type="vertical"/>
            <a v-auth="`update`" @click="disposal(record)">处置</a>
          </template>
        </a-table>

      </div>
      <a-pagination
          @change="onChangePage"
          @showSizeChange="showSizeChange"
          :total="pagination.total"
          :showSizeChanger="true"
          :showQuickJumper="true"
          :defaultPageSize="pagination.defaultPageSize"
          :pageSize="pagination.page_size"
          :pageSizeOptions="pagination.pageSizeOptions"
          :current="pagination.current"
          :showTotal="pagination.showTotal"
          style="width: 100%;display: flex;flex-direction: row;justify-content: flex-end;margin-top: 15px"
      ></a-pagination>
    </a-card>
  </div>
</template>

<script>

import {mapGetters} from "vuex";
import PageHeadArea from "../module/pageHeadArea.vue";
import storage from "store";
import {DEPT_ID, ORGANIZATION_ID, USER_TOKEN} from "@/store/mutation-types";
import axios from "axios";
import {
  delete_asset,
} from "@/services/manage";
import {
  file_upload_url,
  get_device_list,
} from "../../services/deviceManagement";
import {
  deleteDevice,
  deleteDeviceMaintenanceProject,
  deleteDeviceMaintenanceType,
  deleteDeviceMaintenanceTypeProjectRelation, fileUpload,
  getAllDeviceGradeList,
  getDeviceInspectionAllList,
  getDeviceInspectionProjectList,
  getDeviceInspectionProjectRelationList,
  getDeviceInspectionProjectResultList,
  getDeviceList,
  getDeviceMaintenanceProjectList,
  getDeviceMaintenanceTypeList,
  getDeviceMaintenanceTypeProjectRelationList,
  getDeviceManageInfoList,
  getDevicePartsRelationList,
  getDeviceReformInfoList,
  getDeviceRepairAllList,
  getDeviceTypeList,
  getOrganizationList,
  getPartsById,
  getRelationByDeviceId,
  getSupplierById,
  getSupplierIdByName,
  getUserNameById,
  listDeviceInspectionProject,
  listDeviceMaintenanceProject,
  listSpareParts,
  save_device_inspection_project_result,
  saveDevice,
  saveDeviceInspectionProject,
  saveDeviceInspectionProjectRelation,
  saveDeviceMaintenanceProject,
  saveDeviceMaintenanceType,
  saveDeviceMaintenanceTypeProjectRelation,
  saveDeviceManageInfo,
  saveDevicePartsRelation,
  saveDeviceReformInfo,
  saveSpareParts
} from "../../utils/interface";
import {Message, message} from "ant-design-vue";
import {getTimestamp} from "../../utils/util";
const data = []
const columns = [
  { title: '设备编码', width: 120, align:'center',dataIndex: 'code', key: 'code'},
  { title: '设备名称', width: 120, align:'center',dataIndex: 'name', key: 'name'},
  { title: '规格型号', width: 120, align:'center',dataIndex: 'specification', key: 'specification'},
  { title: '生产厂家', width: 120, align:'center',dataIndex: 'supplier_name', key: 'supplier_name'},
  { title: '出厂编号', width: 120, align:'center',dataIndex: 'factory_number', key: 'factory_number'},
  { title: '到厂日期', width: 120, align:'center',dataIndex: 'arrival_date', key: 'arrival_date'},
  { title: '验收日期', width: 120, align:'center',dataIndex: 'acceptance_date', key: 'acceptance_date'},
  { title: '质保验收日期', width: 120, align:'center',dataIndex: 'warranty_acceptance_date', key: 'warranty_acceptance_date'},
  { title: '设备状态', width: 120, align:'center',dataIndex: 'status_description', key: 'status_description'},
  { title: '设备类型', width: 120, align:'center',dataIndex: 'device_type_name', key: 'device_type_name'},
  { title: '设备等级', width: 120, align:'center',dataIndex: 'device_grade_name', key: 'device_grade_name'},
  { title: '安装位置', width: 120, align:'center',dataIndex: 'location', key: 'location'},
  { title: '设备功率/KW', width: 120, align:'center',dataIndex: 'true_device_power', key: 'true_device_power'},
  { title: '资产编码', width: 120, align:'center',dataIndex: 'asset_code', key: 'asset_code'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    fixed: 'right',
    width: 180,
    scopedSlots: { customRender: 'action' }
  }
]

const key1Columns = [
  { title: '编码', width: 120, align:'center',dataIndex: 'code', key: 'code'},
  { title: '名称', width: 120, align:'center',dataIndex: 'name', key: 'name'},
  { title: '规格', width: 120, align:'center',dataIndex: 'specification', key: 'specification'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    fixed: 'right',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const key2Columns = [
  { title: '编码', width: 120, align:'center',dataIndex: 'code', key: 'code'},
  { title: '名称', width: 120, align:'center',dataIndex: 'name', key: 'name'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    fixed: 'right',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const key3Columns = [
  { title: '编码', width: 120, align:'center',dataIndex: 'code', key: 'code'},
  { title: '名称', width: 120, align:'center',dataIndex: 'name', key: 'name'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    fixed: 'right',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const key4Columns = [
  { title: '编码', width: 120, align:'center',dataIndex: 'id', key: 'id'},
  { title: '名称', width: 120, align:'center',dataIndex: 'name', key: 'name'},
  { title: '规格', width: 120, align:'center',dataIndex: 'specification', key: 'specification'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    fixed: 'right',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const key5Columns = [
  { title: '电话', width: 120, align:'center',dataIndex: 'phone', key: 'phone'},
  { title: '联系人', width: 120, align:'center',dataIndex: 'contact', key: 'contact'},
  { title: '类型', width: 120, align:'center',dataIndex: 'type', key: 'type'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    fixed: 'right',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const key6Columns = [
  { title: '编码', width: 120, align:'center',dataIndex: 'id', key: 'id'},
  { title: '名称', width: 120, align:'center',dataIndex: 'name', key: 'name'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const detail1Columns = [
  { title: '编码', width: 120, align:'center',dataIndex: 'code', key: 'code'},
  { title: '名称', width: 120, align:'center',dataIndex: 'name', key: 'name'},
  { title: '规格', width: 120, align:'center',dataIndex: 'specification', key: 'specification'},
  { title: '库存', width: 120, align:'center',dataIndex: 'now_inventory', key: 'now_inventory'},
]

const detail2Columns =[
  { title: '保养单号', width: 120, align:'center',dataIndex: 'code', key: 'code'},
  { title: '日期', width: 120, align:'center',dataIndex: 'create_time', key: 'create_time'},
  { title: '保养人', width: 120, align:'center',dataIndex: 'user_name', key: 'user_name'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }
]
const detail3Columns = [ { title: '点检单号', width: 120, align:'center',dataIndex: 'code', key: 'code'},
  { title: '日期', width: 120, align:'center',dataIndex: 'create_time', key: 'create_time'},
  { title: '点检人', width: 120, align:'center',dataIndex: 'user_name', key: 'user_name'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const detail4Columns = [
  { title: '维修单号', width: 120, align:'center',dataIndex: 'code', key: 'code'},
  { title: '日期', width: 120, align:'center',dataIndex: 'repair_time', key: 'repair_time'},
  { title: '维修人', width: 120, align:'center',dataIndex: 'user_name', key: 'user_name'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const detail5Columns =[ { title: '编码', width: 120, align:'center',dataIndex: 'id', key: 'id'},
  { title: '名称', width: 120, align:'center',dataIndex: 'name', key: 'name'},
  { title: '规格', width: 120, align:'center',dataIndex: 'specification', key: 'specification'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const detail6Columns = [
  { title: '编码', width: 120, align:'center',dataIndex: 'code', key: 'code'},
  { title: '名称', width: 120, align:'center',dataIndex: 'name', key: 'name'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const detail7Columns =[
  { title: '编码', width: 120, align:'center',dataIndex: 'code', key: 'code'},
  { title: '名称', width: 120, align:'center',dataIndex: 'name', key: 'name'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const detail8Columns =[
  { title: '改造原因', width: 120, align:'center',dataIndex: 'reason', key: 'reason'},
  { title: '改造附件', width: 120, align:'center',dataIndex: 'attachment', key: 'attachment'},
  { title: '改造人', width: 120, align:'center',dataIndex: 'user_name', key: 'user_name'},

  {
    title: '操作',
    align:'center',
    key: 'operation',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }
  ]

const detail9Columns =[
  { title: '处置原因', width: 120, align:'center',dataIndex: 'reason', key: 'reason'},
  { title: '处置附件', width: 120, align:'center',dataIndex: 'attachment', key: 'attachment'},
  { title: '处置人', width: 120, align:'center',dataIndex: 'user_name', key: 'user_name'},
  { title: '处置类型', width: 120, align:'center',dataIndex: 'status_description', key: 'status_description'},

  {
    title: '操作',
    align:'center',
    key: 'operation',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }
]


const maintenanceDetailsColumns =[{ title: '编码', width: 120, align:'center',dataIndex: 'code', key: 'code'},
  { title: '名称', width: 120, align:'center',dataIndex: 'name', key: 'name'},
  {
    title: '操作',
    align:'center',
    key: 'operation',
    fixed: 'right',
    width: 120,
    scopedSlots: { customRender: 'action' }
  }]

const key1Data =[];

const key2Data = [];

const key3Data = [];

const key4Data = [{
  "id": 1,
  "name": "产品A",
  "specification": "规格A"
},
  {
    "id": 2,
    "name": "产品B",
    "specification": "规格B"
  },];
const key5Data = [{"phone": "123456789", "contact": "张三", "type": "类型A"}];

const key6Data = [{
  id: '001',
  name: '产品A',

},
  {
    id: '002',
    name: '产品B',
  },
  {
    id: '003',
    name: '产品C',
  },
  {
    id: '004',
    name: '产品C',
  },
  {
    id: '005',
    name: '产品C',
  }];

const detail1Data = [];

const detail2Data=[];

const detail3Data = [];

const detail4Data = [];

const detail5Data =[{"id": "001", "name": "产品A", "specification": "规格A"}];

const detail6Data = [];

const detail7Data = [];

const detail8Data = [];

const detail9Data = [];

const maintenanceDetailsData = [];
const fileList=[];
const { VUE_APP_USER_TOKEN } = process.env;
export default {
  name: "userAuthority",
  components: {PageHeadArea},
  data() {
    return {
      fileList,
      organizationList:[],
      maintenanceTypeList:[],
      partSearchList:[],
      projectSearchList:[],
      inspectProjectSearchList:[],
      manageText:'',
      department:undefined,
      maintenanceType:undefined,
      reformReason:'',
      selectedRowKeys: [],
      addDeviceCode:'',
      supplierSearchList:[],
      record: {},
      key1Data,
      key1Columns,
      key2Data,
      key2Columns,
      key3Data,
      key3Columns,
      key4Data,
      key4Columns,
      key5Data,
      key5Columns,
      key6Data,
      key6Columns,
      detail1Columns,
      detail1Data,
      detail2Columns,
      detail2Data,
      detail3Columns,
      detail3Data,
      detail4Columns,
      detail4Data,
      detail5Columns,
      detail5Data,
      detail6Columns,
      detail6Data,
      detail7Columns,
      detail7Data,
      detail8Columns,
      detail8Data,
      detail9Columns,
      detail9Data,
      maintenanceDetailsColumns,
      maintenanceDetailsData,
      tableLoading01: false,
      tableLoading02: false,
      tableLoading03: false,
      tableLoading04: false,
      tableLoading05: false,
      tableLoading06: false,
      tableLoadingDetail1:false,
      tableLoadingDetail2:false,
      tableLoadingDetail3:false,
      tableLoadingDetail4:false,
      tableLoadingDetail5:false,
      tableLoadingDetail6:false,
      tableLoadingDetail7:false,
      tableLoadingDetail8:false,
      tableLoadingDetail9:false,
      tableLoadingDetail10:false,
      tableLoadingDetail11:false,
      tableLoadingMaintenanceDetails:false,
      axiosSource: null,
      tabKey: '1',
      title:'',
      tabBarGutter: 0,
      tabBarStyle: {
        color: 'rgba(0, 0, 0, 0.85)'
      },
      bodyStyle: {
        'padding': '0px 24px 0px 24px',
        'font-size': '14px',
        'line-height': '1.5',
        'word-wrap': 'break-word',
      },
      cardMinHeight: 0,
      queryForm: {
        code: '',
        name: '',
        specification:'',
        mask_status: undefined,
        mask_grades: undefined,
      },
      data,
      columns,
      pagination: {
        total: 0,
        page_size: 10,
        defaultPageSize: 10,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['10', '20', '50', '100', '500'],
      },
      tableLoading: false,
      addModal: false,
      canBeEdited: false, //是否可编辑
      isAdd: false, //是否为新增
      spinning: false,

      detailModal:false, //详情弹窗
      canBeQuery:false, //是否可查询

      remodelModal:false,
      disposalModal:false,
      maintenance_detailsModal:false,
      maintenance_detailsModal2:false,
      key1Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      key2Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      key3Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      key4Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      key5Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      key6Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      detail1Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      detail2Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      detail3Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      detail4Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      detail5Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      detail6Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      detail7Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      detail8Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      detail9Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      detail10Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      detail11Pagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      maintenanceDetailsPagination: {
        total: 0,
        page_size: 4,
        defaultPageSize: 4,
        page: 1,
        current: 1,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条记录`,
        pageSizeOptions: ['4', '8', '10', '20', '50'],
      },
      //基础表
      basicForm: {
        allDeviceGradeList2:[],
        allDeviceGradeList:[],//所有设备等级列表
        device_grade_name:'',
        device_type_name:'',
        status_description:'',
        supplier_name:'',
        acceptance_date: '',
        arrival_date: '',
        asset_code: '',
        code:'',
        device_grade_id:'',
        // gradeList:[],// 等级列表
        true_device_power:'',
        device_type_id:'',
        typeList:[],//类型列表
        factory_number:'',
        id:'',
        inspection_cycle:'',
        last_inspection_time:'',
        last_maintenance_time:'',
        location:'',
        maintenance_cycle:'',
        name:'',
        organization_id:'',
        organizationList:[],//组织列表
        remark:'',
        specification:'',
        status:'',
        statusList:[
          {code:null,description: "不限"},
          { code: 1, description: "正常运行" },
          { code: 2, description: "正在检修" },
          { code: 3, description: "正常停机" },
          { code: 4, description: "故障停机" },
          { code: -1, description: "组内没有设备/组内设备没有任何状态值" }
        ],//状态列表
        statusList2:[
          { code: 1, description: "正常运行" },
          { code: 2, description: "正在检修" },
          { code: 3, description: "正常停机" },
          { code: 4, description: "故障停机" },
          { code: -1, description: "组内没有设备/组内设备没有任何状态值" }
        ],//状态列表
        manageStatusList:[
          { code: 1, description: "报废" },
          { code: 2, description: "封存" },
          { code: 3, description: "启动" },
          { code: 4, description: "异动" }
        ],//改造状态列表
        supplier_id:'',
        // supplierList:[],//供应商列表
        tenant_id:'',
        tenantList:[],//租户列表
        warranty_acceptance_date:''
      },
      //rules
      rules:{
        code: [{required: true, message: '请输入编码', trigger: 'blur'}],
        name: [{required: true, message: '请输入名称', trigger: 'blur'}],
        specification: [{required: false, message: '请输入规格', trigger: 'blur'}],
        supplier_id: [{required: false, message: '请选择生产厂家', trigger: 'blur'}],
        supplier_name: [{required: false, message: '请选择生产厂家', trigger: 'blur'}],
        factory_number: [{required: false, message: '请输入出厂编号', trigger: 'blur'}],
        arrival_date: [{required: false, message: '请选择到货日期', trigger: 'blur'}],
        acceptance_date: [{required: false, message: '请选择验收日期', trigger: 'blur'}],
        status_description: [{required: false, message: '请选择设备状态', trigger: 'blur'}],
        device_type_id: [{required: false, message: '请选择设备类型', trigger: 'blur'}],
        device_grade_id: [{required: false, message: '请选择设备等级', trigger: 'blur'}],
        location: [{required: false, message: '请输入安装位置', trigger: 'blur'}],
        asset_code: [{required: false, message: '请输入资产编号', trigger: 'blur'}],
        true_device_power:[{required: false, message: '请输入功率', trigger: 'blur'},
          { validator: (rule, value, callback) => {
              if (value && !/^\d+$/.test(value)) {
                callback(new Error('功率必须为纯数字'));
              } else {
                callback();
              }
            }, trigger: 'blur' }],
        maintenance_cycle:[{required: false, message: '请输入保养周期', trigger: 'blur'},
          { validator: (rule, value, callback) => {
              if (value && !/^\d+$/.test(value)) {
                callback(new Error('保养周期必须为纯数字'));
              } else {
                callback();
              }
            }, trigger: 'blur' }],
        inspection_cycle:[{required: false, message: '请输入检修周期', trigger: 'blur'},
          { validator: (rule, value, callback) => {
              if (value && !/^\d+$/.test(value)) {
                callback(new Error('检修周期必须为纯数字'));
              } else {
                callback();
              }
            }, trigger: 'blur' }],

      },
      //新增下面3个小表addForm
      addFormOfNewDevice:{
        id:'',
        code:'',
        name:'',
        specification:'',
      },

      //相关备品备件表
      sparePartsForm: {
        device_id:'',
        id:'',
        organization_id:'',
        parts_id:'',
        remark:'',
        status:'',
        tenant_id:'',
      }
    }
  },
  watch: {},
  authorize: {
    add: 'insert',
    getAssetLedgerList: 'query',
    reset: 'query',
    query: 'query',
    detail: 'query',
    edit: 'update',
    del: 'delete',
    check: 'check',
  },
  computed: {
    ...mapGetters(['getCardMinHeight']),
  },
  created() {
    this.cardMinHeight = this.getCardMinHeight
  },
  async mounted() {
    //保养类型
    await getDeviceMaintenanceTypeList().then(res=>{
      this.maintenanceTypeList=res
    })

    //获取部门
    await getOrganizationList().then(res=>{
      this.organizationList=res
    })
    this.axiosSource = axios.CancelToken.source();
    await getAllDeviceGradeList().then(res=>{
      this.basicForm.allDeviceGradeList2=[]
      this.basicForm.allDeviceGradeList=[]
      this.basicForm.allDeviceGradeList2=res
      this.basicForm.allDeviceGradeList.push({'id': null, 'name': '不限'})
      res.forEach(item=>{
        this.basicForm.allDeviceGradeList.push(item)
      })
    })
    await getDeviceTypeList().then(res=>{
      this.basicForm.typeList=res
    })
    await this.getDeviceList()
  },
  methods: {
    beforeUpload (file) {
      this.fileList = [...this.fileList, file]
      return false
    },
    // 上传并保存文件
    async saveFile(file, search_table_primary_id, status) {
      const formData = new FormData();
      const uploadUrl = file_upload_url();

      // 构建完整的URL，包括查询字符串参数
      const urlWithParams = new URL(uploadUrl);

      let table_name, table_column_id;
      if (status === 'remodelModal') {
        table_name = 'device_reform_info';
      } else if (status === 'disposalModal') {
        table_name = 'device_manage_info';
      }
      // console.log(table_name);
      table_column_id = null;

      // 添加文件到FormData
      formData.append('file', file);

      // 构建上传参数对象
      const uploadParams = {
        table_primary_id: search_table_primary_id,
        file_type: '1',
        table_name: table_name,
        table_column_id: table_column_id
      };

      // 将参数添加到URL的查询字符串中
      Object.keys(uploadParams).forEach(key => {
        if (uploadParams[key] !== null && uploadParams[key] !== undefined) {
          urlWithParams.searchParams.append(key, uploadParams[key]);
        }
      });
      try {
        const response = await axios.post(urlWithParams.toString(), formData, {
          headers: {
            'Timestamp': getTimestamp(),
            'Authorization': storage.get(VUE_APP_USER_TOKEN), // 确保你的Token格式正确
          },
        });

        // console.log(response);
        if (response.data.code !== '1000') {
          message.error('上传失败');
        } else {
          message.success('上传成功');
        }
        return response;
      } catch (error) {
        console.error('网络错误:', error);
        message.error('上传过程中发生错误');
      }
    },
    // 删除
    handleDownloadFileRemove (data) {
      this.fileList = this.fileList.filter(f => f !== data)

    },
    onSelectChange(selectedRowKeys){
      // console.log('selectedRowKeys changed: ', selectedRowKeys);
      this.selectedRowKeys = selectedRowKeys
    },
    callback (key) { // assetCode
      this.tabKey = key
      this.manageText=''
      //
      this.fileList=[]
      this.addFormOfNewDevice={
        id:'',
        code:'',
        name:'',
        specification:'',
      }
    },

    // 分页切换
    onChangePage (page, pageSize) {
      this.pagination.current = page
      this.pagination.page_size = pageSize
      this.pagination.page = page
      console.log(this.pagination)
      this.getDeviceList()
    },
    showSizeChange(current, size){
      this.pagination.page_size = size
      this.pagination.current = current
      this.pagination.page = current
      this.getDeviceList()
    },
    // 分页切换
    onChangeKey1 (pagination) {
      this.key1Pagination.current = pagination.current
      this.key1Pagination.page_size = pagination.pageSize
      this.key1Pagination.page = pagination.current
    },
    // 分页切换
    onChangeKey2 (pagination) {
      this.key2Pagination.current = pagination.current
      this.key2Pagination.page_size = pagination.pageSize
      this.key2Pagination.page = pagination.current
    },
    // 分页切换
    onChangeKey3 (pagination) {
      this.key3Pagination.current = pagination.current
      this.key3Pagination.page_size = pagination.pageSize
      this.key3Pagination.page = pagination.current
    },
    // 分页切换
    onChangeKey4 (pagination) {
      this.key4Pagination.current = pagination.current
      this.key4Pagination.page_size = pagination.pageSize
      this.key4Pagination.page = pagination.current
    },
    // 分页切换
    onChangeKey5 (pagination) {
      this.key5Pagination.current = pagination.current
      this.key5Pagination.page_size = pagination.pageSize
      this.key5Pagination.page = pagination.current
    },
    // 分页切换
    onChangeKey6 (pagination) {
      this.key6Pagination.current = pagination.current
      this.key6Pagination.page_size = pagination.pageSize
      this.key6Pagination.page = pagination.current
    },
    onChangeDetail1(pagination) {
      this.detail1Pagination.current = pagination.current
      this.detail1Pagination.page_size = pagination.pageSize
      this.detail1Pagination.page = pagination.current
    },
    onChangeDetail2(pagination) {
      this.detail2Pagination.current = pagination.current
      this.detail2Pagination.page_size = pagination.pageSize
      this.detail2Pagination.page = pagination.current
    },
    onChangeDetail3(pagination) {
      this.detail3Pagination.current = pagination.current
      this.detail3Pagination.page_size = pagination.pageSize
      this.detail3Pagination.page = pagination.current
    },
    onChangeDetail4(pagination) {
      this.detail4Pagination.current = pagination.current
      this.detail4Pagination.page_size = pagination.pageSize
      this.detail4Pagination.page = pagination.current
    },
    onChangeDetail5(pagination) {
      this.detail5Pagination.current = pagination.current
      this.detail5Pagination.page_size = pagination.pageSize
      this.detail5Pagination.page = pagination.current
    },
    onChangeDetail6(pagination) {
      this.detail6Pagination.current = pagination.current
      this.detail6Pagination.page_size = pagination.pageSize
      this.detail6Pagination.page = pagination.current
    },
    onChangeDetail7(pagination) {
      this.detail7Pagination.current = pagination.current
      this.detail7Pagination.page_size = pagination.pageSize
      this.detail7Pagination.page = pagination.current
    },
    onChangeDetail8(pagination) {
      this.detail8Pagination.current = pagination.current
      this.detail8Pagination.page_size = pagination.pageSize
      this.detail8Pagination.page = pagination.current
    },
    onChangeDetail9(pagination) {
      this.detail9Pagination.current = pagination.current
      this.detail9Pagination.page_size = pagination.pageSize
      this.detail9Pagination.page = pagination.current
    },
    onChangeDetail10(pagination) {
      this.detail10Pagination.current = pagination.current
      this.detail10Pagination.page_size = pagination.pageSize
      this.detail10Pagination.page = pagination.current
    },
    onChangeDetail11(pagination) {
      this.detail11Pagination.current = pagination.current
      this.detail11Pagination.page_size = pagination.pageSize
      this.detail11Pagination.page = pagination.current
    },
    onChangeMaintenanceDetails(pagination) {
      this.maintenanceDetailsPagination.current = pagination.current
      this.maintenanceDetailsPagination.page_size = pagination.pageSize
      this.maintenanceDetailsPagination.page = pagination.current
    },
    async query() {
      this.pagination.page = 1
      this.pagination.current = 0
      this.pagination.page_size = 10
      this.loading = true
      //保养类型
      await getDeviceMaintenanceTypeList().then(res=>{
        this.maintenanceTypeList=res
      })

      //获取部门
      await getOrganizationList().then(res=>{
        this.organizationList=res
      })
      this.axiosSource = axios.CancelToken.source();
      await getAllDeviceGradeList().then(res=>{
        this.basicForm.allDeviceGradeList2=[]
        this.basicForm.allDeviceGradeList=[]
        this.basicForm.allDeviceGradeList2=res
        this.basicForm.allDeviceGradeList.push({'id': null, 'name': '不限'})
        res.forEach(item=>{
          this.basicForm.allDeviceGradeList.push(item)
        })
      })
      await getDeviceTypeList().then(res=>{
        this.basicForm.typeList=res
      })
      await this.getDeviceList()
    },
    onChangeArrivalDate(value, dateString){
      this.basicForm.arrival_date = dateString

    },
    onChangeAcceptanceDate(value, dateString){
      this.basicForm.acceptance_date=dateString
    },
    onChangeWarrantyAcceptanceDate(value, dateString){
      this.basicForm.warranty_acceptance_date=dateString
    },
    basicFormStatusChange(value){
      this.basicForm.status=value
    },
    basicFormTypeChange(value){

      this.basicForm.device_type_id=value
    },
    basicFormGradeChange(value){
      this.basicForm.device_grade_id=value
    },
    async reset() {
      this.queryForm = {
        code: '',
        name: '',
        specification: '',
        mask_status: undefined,
        mask_grades: undefined,
      }
      await this.getDeviceList()
    },
    async filter() {
      //筛选
      this.pagination.page = 1
      this.pagination.current = 1
      this.pagination.page_size = 10
      this.tableLoading = true
      //请求后端


      await this.getDeviceList({'code':this.queryForm.code,
        'name': this.queryForm.name,
        'specification': this.queryForm.specification,
        'status': this.queryForm.mask_status,
        'device_grade_id': this.queryForm.mask_grades})

      this.tableLoading = false;
    },
    add() {
      this.clearParameter()
      this.addModal = true
      this.canBeEdited = true
      this.isAdd = true
      this.spinning = false
    },
    async deleteDevice() {
      for (const item of this.selectedRowKeys) {
        await deleteDevice({ 'id': item });
      }
      message.success("删除设备成功!");
      // 重新加载
      this.data = [];
      this.selectedRowKeys = [];
      await this.getDeviceList()
    },
    edit(record) {
      this.addModal = true
      this.canBeEdited = true
      this.isAdd = false
      this.echo(record)
    },
    del(id) {
      const params = Object.assign({},{'organization_id': storage.get(ORGANIZATION_ID),'asset_id': id})
      delete_asset(params)
          .then(res => {
            if (res && res.data.code && res.data.code === '1000') {
              this.getAssetLedgerList()
            } else {
              this.$message.error('删除失败',1)
            }
          })
          .catch(err => {
            console.log(err)
            this.$message.error('删除失败',1)
          })
    },
    changeSupplier(item){
      this.basicForm.supplier_id=item.id;
      this.basicForm.supplier_name=item.name;
      this.supplierSearchList=[]
    },
   async detail(record) {
      this.clearParameter2()
      this.detailModal = true
      this.canBeEdited = true
      this.canBeQuery =true
      this.isAdd = true
      await this.echo(record)

     this.tableLoadingDetail1=true;
     this.tableLoadingDetail2 = true
     this.tableLoadingDetail3 = true
     this.tableLoadingDetail4 = true
     this.tableLoadingDetail6 = true
     this.tableLoadingDetail7 = true
     this.tableLoadingDetail8 = true;
     this.tableLoadingDetail9=true;
     //备品备件 {'device_id':device_id}
      await getDevicePartsRelationList({'device_id':record.id}).then(res=>{
        if(res.length===0){
          this.detail1Data = []
          this.tableLoadingDetail1=false;
        }
        this.detail1Data = []
        res.forEach(item =>{
          //通过part_id查相关数据 {'id':part_id}
          getPartsById({'id':item.parts_id}).then(res=>{
            if(res.length===0){
              this.detail1Data = []
              this.tableLoadingDetail1=false;
            }
            //添加字段
            res.forEach(item2 =>{
              this.detail1Data.push(item2)
            })
          })
        })
        this.tableLoadingDetail1=false;
      })
     //保养记录 {'device_id':device_id} -
      await getRelationByDeviceId({'device_id':record.id}).then(
          async res => {
            if(res.length===0){
              this.detail2Data = []
              this.tableLoadingDetail2=false;
            }else{
              this.detail2Data = []
              for (const item of res) {
                item['user_name'] = await getUserNameById(item.create_user)
                this.detail2Data.push(item)
              }

              this.tableLoadingDetail2 = false
            }
          }
      )
     //点检记录 {'device_id':device_id} -
     await getDeviceInspectionAllList({'device_id':record.id}).then(
         async res => {
           if(res.length===0){
             this.detail3Data = []
             this.tableLoadingDetail3=false;
           }else{
             this.detail3Data = []
             for (const item of res) {
               item['user_name'] = await getUserNameById(item.create_user)
               this.detail3Data.push(item)
             }

             this.tableLoadingDetail3 = false
           }

         }
     )
     //维修记录 {'device_id':device_id} -
     await getDeviceRepairAllList({'device_id':record.id}).then(
         async res => {
           if(res.length===0){
             this.detail4Data = []
             this.tableLoadingDetail4=false;
           }else{
             this.detail4Data = []
             for (const item of res) {
               item['user_name'] = await getUserNameById(item.create_user)
               this.detail4Data.push(item)
             }
             this.tableLoadingDetail4 = false
           }

         }
     )
     //保养项目 'device_id':device_id -
        await getDeviceMaintenanceTypeProjectRelationList({'device_id':record.id}).then(async res => {
          if(res.length===0){
            this.detail6Data = []
            this.tableLoadingDetail6=false;
          }else{
            this.detail6Data=[]
            for (const item of res) {
              //{'id':id}
              await getDeviceMaintenanceTypeList({'id':item.maintenance_type_id}).then(res2=>{
                res2.forEach(inItem=>{

                  // 检查 inItem 的 id 是否已经存在于 detail6Data 数组中
                  const exists = this.detail6Data.find(item => item.id === inItem.id);
                  if (!exists) {
                    // 如果不存在，则将 inItem 添加到 detail6Data 数组中
                    this.detail6Data.push(inItem);
                  }

                })
              })
            }
            this.tableLoadingDetail6 = false
          }

        })


     //点检项目 {'device_id':device_id}-
     await getDeviceInspectionProjectRelationList({'device_id':record.id}).then(async res => {
       if(res.length===0){
         this.detail7Data = []
         this.tableLoadingDetail7=false;
       }else{
         this.detail7Data = []
         for (const item of res) {
           //添加根据id找project {'id':check_project_id}
           await getDeviceInspectionProjectList({'id': item.inspection_project_id}).then(res2=>{
             res2.forEach(inItem=>{
               this.detail7Data.push(inItem)
             })
           })
         }
         this.tableLoadingDetail7 = false
       }

     })

     //设备改造-
     await getDeviceReformInfoList({'device_id':record.id}).then(async res => {
       if(res.length===0){
         this.detail8Data = []
         this.tableLoadingDetail8=false;
       }else{
         this.detail8Data = []
         for (const item of res) {
           item['user_name'] = await getUserNameById(item.create_user)
           this.detail8Data.push(item)
         }
         this.tableLoadingDetail8 = false
       }

     })

     //处置记录-
     await getDeviceManageInfoList({'device_id':record.id}).then(async res => {
       if(res.length===0){
         this.detail9Data = []
         this.tableLoadingDetail9=false;
       }else{
         this.detail9Data = []
         for (const item of res) {
           item['status_description'] = this.basicForm.manageStatusList.find(itS => itS.code === item.status)?.description || ''
           item['user_name'] = await getUserNameById(item.create_user)
           this.detail9Data.push(item)
         }


         this.tableLoadingDetail9 = false
       }

     })

     // //向supplierSearchList放初始数据
     // this.supplierSearchList=[]
     // this.supplierSearchList.push({id:record.supplier_id,name:record.supplier_name})
    },
    async echo(record){
      this.record = record
      const basicProperties = ['acceptance_date','arrival_date','asset_code','code','device_grade_id','true_device_power','device_type_id',
      'factory_number','id','inspection_cycle','last_inspection_time','last_maintenance_time',
      'location','maintenance_cycle','name','organization_id','specification','status',
      'supplier_id','warranty_acceptance_date','supplier_name','status_description','device_type_name','device_grade_name']

      for (const item of basicProperties) {
        this.basicForm[item] = record[item]
      }
        // console.log(this.basicForm)
    },
    remodel(record){
      this.remodelModal = true
      this.canBeEdited = true
      this.canBeQuery =true
      this.isAdd = true
      this.fileList=[]
      this.echo(record)
    },
    disposal(record){
      this.disposalModal = true
      this.canBeEdited = false
      this.canBeQuery =true
      this.isAdd = false
      this.fileList=[]
      this.echo(record)
    },
    cancelDetailsModal(){
      this.maintenance_detailsModal = false
      this.canBeEdited = true
      this.canBeQuery =true
      this.isAdd = true

    },
    cancelDetailsModal2(){
      this.maintenance_detailsModal2 = false
      this.canBeEdited = true
      this.canBeQuery =true
      this.isAdd = true
    },
    clearAddMessage(){
      this.addFormOfNewDevice={
        id:'',
        code:'',
        name:'',
        specification:'',
      }
    },
    //删保养项目
    delMaintenanceProject(record){
      //直接删保养项目
      let part_id
      deleteDeviceMaintenanceProject({'id':record.id}).then(res=>{
        //删除关系
        //找关系
        getDeviceMaintenanceTypeProjectRelationList({'device_id':this.record.id,'maintenance_project_id':record.id}).then(res=>{
          let relation_id = res[0].id
          part_id= res[0].maintenance_type_id
          deleteDeviceMaintenanceTypeProjectRelation({'id':relation_id})
        })

      }).then(res=>{
        message.success("删除设备项目类型成功!");
        //重新加载
        this.maintenanceDetails(this.record.id,part_id)
      })
    },
    delMaintenanceProjectType(record){
      //删除保养类别-后删除相关保养项目-删除关系
      let device_id=this.record.id
      let type_id =record.id
      deleteDeviceMaintenanceType({'id':type_id}).then(res1=>{
        //后删除相关保养项目
        //查相关的保养项目-通过relation
        getDeviceMaintenanceTypeProjectRelationList({'device_id':device_id,'maintenance_type_id':type_id}).then(res2=>{
            res2.forEach(item=> {
              //删除保养项目
              deleteDeviceMaintenanceProject({'id':item.maintenance_project_id}).then(res3=>{
                //删除关系
                deleteDeviceMaintenanceTypeProjectRelation({'id':item.id})

              })
            })
        })

      }).then(res=>{
        message.success("删除设备保养类型成功!");
        //重新加载
        //保养项目 'device_id':device_id -
        getDeviceMaintenanceTypeProjectRelationList({'device_id':device_id}).then(async res => {
          if(res.length===0){
            this.detail6Data = []
            this.tableLoadingDetail6=false;
          }else{
            this.detail6Data=[]
            for (const item of res) {
              //{'id':id}
              await getDeviceMaintenanceTypeList({'id':item.maintenance_type_id}).then(res2=>{
                res2.forEach(inItem=>{

                  // 检查 inItem 的 id 是否已经存在于 detail6Data 数组中
                  const exists = this.detail6Data.find(item => item.id === inItem.id);
                  if (!exists) {
                    // 如果不存在，则将 inItem 添加到 detail6Data 数组中
                    this.detail6Data.push(inItem);
                  }

                })
              })
            }
            this.tableLoadingDetail6 = false
          }

        })


      })
    },
    maintenanceDetails(device_id,maintenance_type_id){
      this.maintenanceDetailsData=[]
      this.maintenance_detailsModal = true
      this.canBeEdited = false
      this.canBeQuery =true
      this.isAdd = true
      getDeviceMaintenanceTypeProjectRelationList({device_id:device_id,maintenance_type_id:maintenance_type_id}).then(res=>{
          res.forEach(item=>{
            //拿到project_id找
            getDeviceMaintenanceProjectList({id:item.maintenance_project_id}).then(res=>{
              res.forEach(item2=>{
                this.maintenanceDetailsData.push(item2)
              })
            })
          })
      })
    },
    maintenanceDetails2(record){
      this.maintenance_detailsModal2 = true
      this.canBeEdited = true
      this.canBeQuery =true
      this.isAdd = true
      this.record= record
      this.maintenanceDetailsData=[]
      this.maintenanceDetailsData= record.subList
    },
    addMaintenanceProjectDetail(){
      const item = this.key2Data.find(item => item === this.record);
      if (item) {
        item.subList.push({
          code:this.addFormOfNewDevice.code,
          name:this.addFormOfNewDevice.name,
        })

        this.maintenanceDetailsData = item.subList
      }
      this.clearAddMessage()

    },
    delAddMaintenanceProject(record){
      const item = this.key2Data.find(item => item === this.record);
      if (item) {
        const item2= item.subList.find(item => item === record);
        //删除item2
        item.subList.splice(item.subList.indexOf(item2),1)
      }
    },
    clearParameter() {
      this.tabKey = '1'
      this.record = {}

      Object.keys(this.basicForm).forEach(key => {
        if (!Array.isArray(this.basicForm[key])) {
          this.basicForm[key] = undefined
        }
      });
      this.key1Data=[]
      this.key2Data=[]
      this.key3Data=[]
      this.key4Data=[]
      this.key5Data=[]
      this.key6Data=[]
      this.maintenanceDetailsData=[]
    },
    clearParameter2() {
      this.tabKey = '1'
      this.record = {}

      Object.keys(this.basicForm).forEach(key => {
        if (!Array.isArray(this.basicForm[key])) {
          this.basicForm[key] = undefined
        }
      });
      this.detail1Data=[]
      this.detail2Data=[]
      this.detail3Data=[]
      this.detail4Data=[]
      this.detail5Data=[]
      this.detail6Data=[]
      this.detail7Data=[]
      this.detail8Data=[]
      this.detail9Data=[]

      this.maintenanceDetailsData=[]
    },
    handleCancel() {
      this.reformReason=''
      this.remodelModal = false
      this.canBeEdited = false
      this.canBeQuery =false
      this.isAdd = false
    },
    handleCancel0() {
      this.addModal = false
      this.canBeEdited = false
      this.isAdd = false
      this.tabKey = '1'
    },
    handleCancel1(){
      this.detailModal = false
      this.canBeEdited = false
      this.canBeQuery =false
      this.isAdd = false
      this.tabKey = '1'
    },
    handleCancel2(){
      this.manageText = ''
      this.disposalModal = false
      this.canBeEdited = false
      this.canBeQuery =false
      this.isAdd = false
      this.tabKey = '1'
    },
    reformReasonSubmit(){

      if(this.reformReason==='' || this.reformReason===undefined){
        message.error("请输入改造原因！")
        return
      }
      saveDeviceReformInfo({'device_id':this.record.id,'reason':this.reformReason}).then(async res => {
        if (res.code !== '1000') {
          // console.log(res)
          message.error("提交失败！")
          return
        }
        if (this.fileList.length > 0) {
          //取id
          let search_info_id = res.data.id
          for (const fileItem of this.fileList) {
            //保存
            await this.saveFile(fileItem, search_info_id,'remodelModal')
          }
        }
        message.success("提交成功！")
      })
      this.remodelModal = false
      this.canBeEdited = false
      this.canBeQuery =false
      this.isAdd = false

      this.reformReason=''
    },
    manageTextSubmit(){
      let status=parseInt(this.tabKey, 10)
      if(this.manageText===''){
        message.error("请输入处理意见！")
      }else{
        if(status===4&& this.department===undefined){
          message.error("请选择部门！")

        }
        else if(status===2&& this.maintenanceType===undefined){
          message.error("请选择保养类型！")

        }
        else{
          saveDeviceManageInfo({'device_id':this.record.id,
            'reason':this.manageText,
            'department_id':status===4?this.department:undefined,
            'maintenance_category_before':status===2?this.maintenanceType:undefined,
            'status':status}).then(async res => {
                  if (res.code !== '1000') {
                    // console.log(res)
                    message.error("提交失败！")
                    return
                  }
                  if (this.fileList.length > 0) {
                    //取id
                    let search_info_id = res.data.id
                    for (const fileItem of this.fileList) {
                      //保存
                      await this.saveFile(fileItem, search_info_id,'disposalModal')
                    }
                  }
                  message.success("提交成功！")
          })
          //结束
          this.manageText = ''
          this.disposalModal = false
          this.canBeEdited = false
          this.canBeQuery =false
          this.isAdd = false
          this.tabKey = '1'
        }


      }
    },
    async submitAndSaveDetail() {
      let flag=true
      //检查code是否重复
      if(this.record.code!==this.basicForm.code){
        let codeUniqueList =  await getDeviceList({'code':this.basicForm.code})
        for (let i = 0; i < codeUniqueList.length; i++) {
          if(codeUniqueList[i].code===this.basicForm.code) {
            flag = false
            break;
          }
        }
      }


      console.log(flag)
      if(flag===false && this.addModal===true){
        message.error("设备编码重复!无法新增!")
      }else if(this.basicForm.code!==this.record.code && this.detailModal===true && flag===false){
        message.error("设备编码重复!无法修改!")
      }
      else if(flag===true)
      {
        this.addDeviceCode=this.basicForm.code
        //保存
        await saveDevice({
          'id':this.basicForm.id,
          'code':this.basicForm.code,
          'name':this.basicForm.name,
          'specification':this.basicForm.specification,
          'supplier_id':this.basicForm.supplier_name===''?null:this.basicForm.supplier_id,
          'factory_number':this.basicForm.factory_number,
          'arrival_date':this.basicForm.arrival_date,
          'acceptance_date':this.basicForm.acceptance_date,
          'status':this.basicForm.status,
          'warranty_acceptance_date':this.basicForm.warranty_acceptance_date,
          'device_grade_id':this.basicForm.device_grade_id,
          'device_type_id':this.basicForm.device_type_id,
          'true_device_power':this.basicForm.true_device_power,
          'location':this.basicForm.location,
          'asset_code':this.basicForm.asset_code,
          'maintenance_cycle':this.basicForm.maintenance_cycle,
          'inspection_cycle':this.basicForm.inspection_cycle,
        }).then(async res => {
          console.log(res)
          if (res === "OK") {
            if(this.addModal===true){
              message.success("新增成功!");

            }else if(this.detailModal===true){
              message.success("修改成功!");
            }

          }
          //更新
          await this.getDeviceList()
        })

        this.handleCancel1()
        this.handleCancel0()
        this.clearAddMessage()
      }
    },

    //新增
    async submitAndSaveDetailMore() {
      //查询是否有值code name
      // console.log(this.basicForm)

       if(this.basicForm.code===undefined|| this.basicForm.name===undefined || this.basicForm.code===''|| this.basicForm.name===''){
         message.error("请输入设备编码和设备名称！")
         return
       }
         //先查询code是否重复
         let codeUniqueList =  await getDeviceList({'code':this.basicForm.code})
         let flag=true
         if(codeUniqueList.length>0){
           for (let i = 0; i < codeUniqueList.length; i++) {
             if(codeUniqueList[i].code===this.basicForm.code) {
               flag = false
               break;
             }
           }
         }
         if(flag===false ){
           message.error("设备编码重复！")
           return
         }
           await this.submitAndSaveDetail().then( res => {
             getDeviceList({'code': this.addDeviceCode}).then(res1 => {
               let searchOne = res1.find(res1It=>res1It.code===this.addDeviceCode)
               let device_id = searchOne.id
               //加关系
               //加备品备件
               this.key1Data.forEach(item => {
                 //加relation
                 console.log({'device_id':device_id,'parts_id':item.id})
                 saveDevicePartsRelation({'device_id':device_id,'parts_id':item.id})

               })
               //加保养类型
               this.key2Data.forEach(item => {
                 if (item.subList.length > 0) {
                   saveDeviceMaintenanceType({'code': item.code, 'name': item.name}).then(res4 => {

                     // 找type_id
                     getDeviceMaintenanceTypeList({'code': item.code}).then(res5 => {
                       let searchType = res5.find(res5It=>res5It.code===item.code)
                       let type_id = searchType.id
                       //加project
                       //
                       item.subList.forEach(subItem => {
                         saveDeviceMaintenanceProject({'code': subItem.code, 'name': subItem.name}).then(res6 => {
                           //拿project_id
                           getDeviceMaintenanceProjectList({'code': subItem.code}).then(res7 => {
                             let searchProject = res7.find(res7It=>res7It.code===subItem.code)
                             let project_id = searchProject.id
                             //加relation
                             saveDeviceMaintenanceTypeProjectRelation({
                               'device_id': device_id,
                               'maintenance_type_id': type_id,
                               'maintenance_project_id': project_id
                             })

                           })
                         })

                       })
                     })
                   })
                 }else{
                   message.error("保养类型无关联项目!");
                 }
               })
               //加点检项目
               this.key3Data.forEach(item => {
                 saveDeviceInspectionProject({'code':item.code,'name':item.name}).then(res8=>{
                   //拿project_id
                   getDeviceInspectionProjectList({'code':item.code}).then(res9=>{
                     let searchInspectionProject = res9.find(res9It=>res9It.code===item.code)
                     let project_id = searchInspectionProject.id
                     //加relation
                     saveDeviceInspectionProjectRelation({'device_id':device_id,'inspection_project_id':project_id})

                   })
                 })


               })

             })
           }).then(async res => {
             // 重新加载
             this.data = [];
             await this.getDeviceList();
           })



    },
    async getPartListByPartCode(part_code){
      await listSpareParts({'code': part_code}).then(res => {
        this.partSearchList = []
        res.slice(0, 10).forEach(item => {
          this.partSearchList.push({
            id: item.id,
            code:item.code,
            name: item.name,
            specification:item.specification
          })
        })
      })
    },
    async getPartListByPartName(part_name) {
      await listSpareParts({'name': part_name}).then(res => {
        this.partSearchList = []
        res.slice(0, 10).forEach(item => {
          this.partSearchList.push({
            id: item.id,
            code:item.code,
            name: item.name,
            specification:item.specification
          })
        })
      })
    },
    async getProjectTypeListByCode(project_code) {
      await getDeviceMaintenanceTypeList({'code': project_code}).then(res => {
        this.projectSearchList = []
        res.slice(0, 10).forEach(item => {
          this.projectSearchList.push({
            id: item.id,
            code: item.code,
            name: item.name,
          })
        })
      })
    },
    async getInspectProjectListByCode(project_code) {
      await listDeviceInspectionProject({'code': project_code}).then(res => {
        this.inspectProjectSearchList = []
        res.slice(0, 10).forEach(item => {
          this.inspectProjectSearchList.push({
            id: item.id,
            code: item.code,
            name: item.name,
          })
        })
      })
    },
    async getInspectProjectListByName(project_name) {
      await listDeviceInspectionProject({'name': project_name}).then(res => {
        this.inspectProjectSearchList = []
        res.slice(0, 10).forEach(item => {
          this.inspectProjectSearchList.push({
            id: item.id,
            code: item.code,
            name: item.name,
          })
        })
      })
    },
    //getProjectTypeListByName
    async getProjectTypeListByName(project_name) {
      await getDeviceMaintenanceTypeList({'name': project_name}).then(res => {
        this.projectSearchList = []
        res.slice(0, 10).forEach(item => {
          this.projectSearchList.push({
            id: item.id,
            code: item.code,
            name: item.name,
          })
        })
      })
    },
    getDeviceList(params){
      this.tableLoading=true;
      const paramsAll = Object.assign({}, params, {
        "page": this.pagination.page,
        "page_size": this.pagination.page_size
      });
      // console.log(paramsAll)

      return new Promise(resolve => {
        get_device_list(paramsAll).then(({data: res}) => {
          if (res.code === '1000'){
            this.pagination.total = res.extension.total+(this.pagination.current-1)*this.pagination.page_size
            // console.log(res.extension.total)
            this.data = []
            // this.data = res.data
            res.data.slice(0, this.pagination.page_size).forEach(item =>{
              //
              //添加供应商信息到list
              if(item.supplier_id===''||item.supplier_id===null) {
                item['supplier_name'] = undefined
                //添加设备状态
                if(item.status!==null && item.status!=='' && item.status!==undefined){
                  item['status_description'] = this.basicForm.statusList.find(status => status.code === item.status)?.description || '';
                }else{
                  item['status_description'] = ''

                }
                this.data.push(item)
              }
              else{
                getSupplierById(item.supplier_id).then(res=>{
                  if(res.length===0){
                    item['supplier_name'] = undefined
                  }else{
                    item['supplier_name'] = res.data.name
                  }

                }).then(()=>{
                  //添加设备状态
                  if(item.status!==null && item.status!=='' && item.status!==undefined){
                    item['status_description'] = this.basicForm.statusList.find(status => status.code === item.status)?.description || '';
                  }else{
                    item['status_description'] = ''

                  }
                  this.data.push(item)
                })

              }
              //
            })
            console.log(this.data)
          } else if (res.code === '1002') {
            console.log(res.msg);
            this.data = []
          }
          this.tableLoading = false
          resolve()
        })
            .catch(err => {
              console.log(err)
              this.data = []
              this.tableLoading = false
              resolve()
            })
      })

    },
    //addPart提交
    addPart(){
      //查重
      const existingDevice = this.key1Data.find(device =>
          device.id === this.addFormOfNewDevice.id &&
          device.code === this.addFormOfNewDevice.code &&
          device.name === this.addFormOfNewDevice.name &&
          device.specification === this.addFormOfNewDevice.specification
      );

      if (existingDevice) {
        // 如果设备已存在，则不添加，并给出提示
        message.error('设备已存在,请勿重复添加!');
      }
      else
      {
        //先放到数组里
        this.key1Data.push({
          id:this.addFormOfNewDevice.id,
          code:this.addFormOfNewDevice.code,
          name:this.addFormOfNewDevice.name,
          specification:this.addFormOfNewDevice.specification,
        })
        //清空表单
        this.clearAddMessage()
      }


    },
    //删除part
    delKey1Data(record){
      const index = this.key1Data.findIndex(item => item === record);
      if (index !== -1) {
        this.key1Data.splice(index, 1);
      }
    },
    delKey2Data(record){
      const index = this.key2Data.findIndex(item => item === record);
      if (index !== -1) {
        this.key2Data.splice(index, 1);
      }
    },
    delKey3Data(record){
      const index = this.key3Data.findIndex(item => item === record);
      if (index !== -1) {
        this.key3Data.splice(index, 1);
      }
      this.key2Data.forEach(item=>{
        if(item.type===record){
          this.key2Data.splice(item, 1);
        }
      })
    },
    changePart(item){
      console.log(item)
      this.addFormOfNewDevice.code= item.code
      this.addFormOfNewDevice.name= item.name
      this.addFormOfNewDevice.id =item.id
      this.addFormOfNewDevice.specification=item.specification
      this.partSearchList=[]
    },
    changeProject(item){
      this.addFormOfNewDevice.code= item.code
      this.addFormOfNewDevice.name= item.name
      this.addFormOfNewDevice.id =item.id
      this.projectSearchList=[]
    },
    changeInspectProject(item){
      this.addFormOfNewDevice.code= item.code
      this.addFormOfNewDevice.name= item.name
      this.addFormOfNewDevice.id =item.id
      this.inspectProjectSearchList=[]
    },
    addMaintenanceProjectType(){
      //查重
      const existingDevice = this.key2Data.find(deviceType =>
          deviceType.id === this.addFormOfNewDevice.id &&
          deviceType.code === this.addFormOfNewDevice.code &&
          deviceType.name === this.addFormOfNewDevice.name
      );
      if (existingDevice) {
        // 如果设备已存在，则不添加，并给出提示
        message.error('设备类型已存在,请勿重复添加!');
      }else{
        this.key2Data.push({
          id:this.addFormOfNewDevice.id,
          code:this.addFormOfNewDevice.code,
          name:this.addFormOfNewDevice.name,
          subList:[]
        })
        //清空表单
        this.clearAddMessage()
      }

    },
    addInspectProject(){
      //查重
      const existing = this.key3Data.find(project =>
          project.id === this.addFormOfNewDevice.id &&
          project.code === this.addFormOfNewDevice.code &&
          project.name === this.addFormOfNewDevice.name
      );
      if (existing) {
        message.error("点检项目已存在，请勿重复添加")
      }
      else{
        this.key3Data.push({
          id:this.addFormOfNewDevice.id,
          code:this.addFormOfNewDevice.code,
          name:this.addFormOfNewDevice.name,
        })
        //清空表单
        this.clearAddMessage()
      }

    },


    // 通过supplier_name查supplier_id supplierSearchList 查生产厂家
    async getSupplierIdByNameLimit(supplier_name) {
      await getSupplierIdByName(supplier_name).then(res => {
        //添加res中值到supplierSearchList
        this.supplierSearchList = []
        res.slice(0, 10).forEach(item => {
          this.supplierSearchList.push({
            id: item.id,
            name: item.name
          })
        })
      })
    },

  },
  beforeDestroy() {
    if (this.axiosSource) {
      this.axiosSource.cancel('Request canceled due to page navigation.');
    }
  }
}
</script>

<style scoped lang="less">
.aPopover{
}
.aPopover:hover {
  background-color: #EA5413;
}
.dataBox{
  margin-top: 20px;
}

.hide-scrollbar::-webkit-scrollbar {
  display: none; /* 隐藏滚动条 */
}

::-webkit-scrollbar {
  display: none; /* 隐藏滚动条 */
}
.hide-scrollbar {
  -ms-overflow-style: none;  /* IE 和 Edge */
  scrollbar-width: none;  /* Firefox */
  overflow-y: scroll; /* 保持内容可滚动 */
}
.demo-infinite-container {
  margin-top: 0px;
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  overflow: auto;
  padding: 8px 24px;
  height: 300px;
}
/deep/ .ant-form-inline .ant-form-item-with-help{
  margin-bottom: 0px;
}
/deep/ .ant-input[disabled]{
  pointer-events: none;
  color: #000000d9;
  background-color: #f5f5f5;
  cursor: not-allowed;
  opacity: 1;
}
/deep/ .unit .ant-select-selection--single{
  margin-left: 0px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: 0;
}
/deep/ .ant-select-disabled .ant-select-selection {
  background-color: #fff;
}
/deep/ .ant-input[disabled]{
  pointer-events: none;
  color: #000000d9;
  background-color: #fff;
  cursor: not-allowed;
  opacity: 1;
}
/deep/ .ant-input-number-disabled{
  pointer-events: none;
  color: #000000d9;
  background-color: #fff;
  cursor: not-allowed;
  opacity: 1;
}
</style>